<template>
	<view class="bhome">
		<view class="bigbox" style="overflow:auto;">
			<block v-for="(item,index) in res.data.data">
				<view class="item">
					<view class="info">
						<view class="activity_title">{{item.name}}</view>
						<view class="activity_resp">
							<view class="title">负责单位</view>{{item.competitionType}}
						</view>
						<view class="activity_deadline">
							<view class="title">通知截至</view>{{item.endTime}}
						</view>
					</view>
						
					<view class="item_btn">
						<view class="apply">
							<navigator @click="addApply(item.id)">报名</navigator>
						</view>
						<view class="detail">
							<navigator :url="'./huodong_detail?id='+item.id" @click="giveHistoryToBack(item.id)">详情</navigator>
						</view>
					</view>
				</view>
			</block>
		</view>
	</view>
</template>

<script>
	export default {
		
		
		
		data() {
			return {
				res:{},
				student: uni.getStorageSync("student"),
				tables: [
					{name:'互联网+比赛',fuze:'学生创协',time:'2022.4.12'},
					{name:'运动会项目报名',fuze:'校学生会',time:'2022.4.12'},
					{name:'互联网+比赛',fuze:'学生创协',time:'2022.4.12'},
					{name:'运动会项目报名',fuze:'校学生会',time:'2022.4.12'},
					{name:'互联网+比赛',fuze:'学生创协',time:'2022.4.12'},
					{name:'运动会项目报名',fuze:'校学生会',time:'2022.4.12'},
					{name:'互联网+比赛',fuze:'学生创协',time:'2022.4.12'},
					{name:'运动会项目报名',fuze:'校学生会',time:'2022.4.12'},
					{name:'互联网+比赛',fuze:'学生创协',time:'2022.4.12'},
					{name:'运动会项目报名',fuze:'校学生会',time:'2022.4.12'},
					{name:'互联网+比赛',fuze:'学生创协',time:'2022.4.12'},
					{name:'运动会项目报名',fuze:'校学生会',time:'2022.4.12'},
					{name:'互联网+比赛',fuze:'学生创协',time:'2022.4.12'},
					{name:'运动会项目报名',fuze:'校学生会',time:'2022.4.12'},
					{name:'互联网+比赛',fuze:'学生创协',time:'2022.4.12'},
					{name:'运动会项目报名',fuze:'校学生会',time:'2022.4.12'},
					{name:'互联网+比赛',fuze:'学生创协',time:'2022.4.12'},
					{name:'运动会项目报名',fuze:'校学生会',time:'2022.4.12'},
				],
			}
		},
		
		// onLoad() {
		// 	this.load()
		// },
	
		
		onShow(option) {
			this.load()
		},
		methods: {
			load(){
				console.log(this.tables)
				uni.request({
					url:'http://106.52.97.99:8085/active/activeList',
					method:'POST',
					success: (res) => {
						this.res=res,
						console.log("6666" + res)
					}
				})
			},
			giveHistoryToBack(id) {
				console.log(this.student.no)
				var myDate = new Date();
				uni.request({
					url:'http://106.52.97.99:8085/history/add',
					method:'POST',
					data:{
						"no":this.student.no,
						"activeId":id,
						"time":myDate.toLocaleTimeString()
					},
					success: (res) => {
						this.res=res,
						console.log(res)
					}
				})
			},
			addApply(id){
				uni.showModal({
					title:'提示',
					content:'确定报名吗',
					success: (sn) => {
						if(sn.confirm){
							uni.getStorage({
								key:'student',
								success: (student1) => {
									this.student=student1,
									console.log(this.student.data.no),
									uni.request({
										url:'http://106.52.97.99:8085/apply/addApplyActive',
										method:'POST',
										data:{
											"no":this.student.data.no,
											"id":id
										},
										success: (pes) => {
											console.log(pes)
											if(pes.data.resultCode==202){
												uni.showToast({
													title:"已报名过该活动!"
												})
											}
											else{
												uni.showToast({
													title:"报名成功!"
												})
											}
										}
									})
								}
							})
						}
					}
				})
			}
		}
	}
</script>

<style>
.bigbox{
	position: fixed;
	width: 100%;
	height: 95%;
}
.bigbox .item{
	display: flex;
	padding: 25rpx 0;
	border-bottom: 2rpx #eee solid;
	padding-left: 30rpx;
}
.bigbox .item:last-child{
	margin-bottom: 100rpx;
}
.bigbox .item .info{
	flex: 1;
}
.bigbox .item .activity_title{
	font-size: 36rpx;
	color: #212121;
	padding-bottom: 20rpx;
	font-weight: 600;
}
.bigbox .item .activity_deadline,
.bigbox .item .activity_resp
{
	color: #424242;
	font-size: 30rpx;
	margin-bottom: 10rpx;
}
.bigbox .item .activity_deadline .title,
.bigbox .item .activity_resp .title{
	display: inline-block;
	color: #616161;
	margin-right: 30rpx;
}
.bigbox .item .item_btn{
	display: flex;
	flex-direction: column;
	height: 100%;
	justify-content: center;
}
.bigbox .item .item_btn .apply navigator,
.bigbox .item .item_btn .detail navigator{
	display: inline-block;
	padding: 10rpx 23rpx;
	border-radius: 3px;
	background-color: #2196F3;
	margin-top: 20rpx;
	margin-right: 30rpx;
	color: #fff;
	font-size: 25rpx;
}
.bigbox .item .item_btn .detail navigator{
	background-color: #fff;
	border: 2rpx solid #2196F3;
	color: #2196F3;
}

</style>
